'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    var { key, active } = ctx.params;
    // var key = JSON.stringify("user");
    //获取model
    var m = ctx.service.common.getModel(key);
    active = `${ctx.request.method.toLocaleLowerCase()}_${active}`;

    var server = ctx.service.common.getServer(key);
    // if (m && !server) {
    //   server = ctx.service.common.getServer(m.name);
    // }
    if (server && server[active]) {
      var x = await server[active](m, ctx.query, ctx.request.body);
      if (ctx.body === undefined) {
        ctx.body = x;
      }
      return;
    }

    var dat = await ctx.service.common[active](m, ctx.query, ctx.request.body, server);
    if (ctx.body === undefined) {
      ctx.body = await ctx.service.common.s(dat);
    }


  }
}

module.exports = HomeController;
